package com.jiawa.train.business.mq;

import com.alibaba.fastjson.JSON;
import com.jiawa.train.business.dto.StockDeductDTO;
import com.jiawa.train.business.service.DailyTrainTicketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.function.Consumer;

@Service
public class StockDeductConsumer {

    private static final Logger LOG = LoggerFactory.getLogger(StockDeductConsumer.class);

    @Resource
    private DailyTrainTicketService dailyTrainTicketService;

    @Bean
    public Consumer<StockDeductDTO> stockDeduct() {
        return stockDeductDTO -> {
            LOG.info("获取到扣减库存消息：{}", JSON.toJSONString(stockDeductDTO));
            dailyTrainTicketService.deductStock(stockDeductDTO);
        };
    }
} 